namespace Study404 {



  // 检测的是对象的原型链
  class Animal {
    name: string;
    constructor(name: string) {
      this.name = name;
    }
  }

  class Dog extends Animal {
    breed: string;
    constructor(name: string, breed: string) {
      super(name);
      this.breed = breed;
    }
  }

  let myDog = new Dog("Buddy", "Golden Retriever");

  console.log(myDog instanceof Dog); // true
  console.log(myDog instanceof Animal); // true
  console.log(myDog instanceof Object); // true



  class Bird {
    fly() {
      console.log("Flying...");
    }

    fly2() {
      console.log("Flying...");
    }
  }

  class Fish {
    swim() {
      console.log("Swimming...");
    }
  }



  // 必考
  function move(params: Bird | Fish) {
    // (params as Bird).fly() // params.fly is not a function

    // instanceof 与类型保护
    if (params instanceof Bird) {
      params.fly()
      params.fly2()
    }

    if (params instanceof Fish) {
      params.swim()
    }

  }


  move(new Fish)



  // 抽象类
  abstract class Car {
    abstract drive(): void;
  }

  class Sedan implements Car {
    drive() {
      console.log("Driving a sedan...");
    }
  }

  let myCar: Car = new Sedan();

  console.log(myCar instanceof Sedan); // true
  console.log(myCar instanceof Car); // false, 因为 `Car` 是抽象类，不是类




}